import { ref } from 'vue'
import { useIntersectionObserver } from '@vueuse/core'
export const userLanJiazai = (fn) => {
  const el = ref(null)
  const goods = ref([])
  const findHots = () => {
    fn.then((data) => {
      goods.value = data.result
      // 主动停止检测元素可见性 只发送一次请求
      stop()
    })
  }
  // 懒加载
  const { stop } = useIntersectionObserver(el, ([{ isIntersecting }]) => {
    if (isIntersecting) {
      return findHots()
    }
  })
  return { goods, el }
}
